
$(function () {
    js1();
    js2();
    var searchURL = window.location.search;
    searchURL = searchURL.substring(1, searchURL.length);
    var targetPageId = searchURL.split("=")[1];
    function js1() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('js1'));

        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            toolbox: {

                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: [],
                    axisTick: {
                        alignWithLabel: true,
                        axisTick: { //关键设置，坐标轴刻度也不显示
                            show: false
                        },
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLine: { //关键设置，不显示X轴线条
                        show: false
                    },
                }
            ],
            series: [
                {
                    name: '数量',
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            color: function(params) {
                                // 给出颜色组
                                var colorList = ['#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f'];
                                return colorList[params.dataIndex]
                            },
                        }
                    },
                    data: []
                }
            ]
        };
        // 定义x、y轴数据数组
        var job_names=[];
        var job_name_nums=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/job_name/"+targetPageId,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    job_names.push(res[i].job_name);
                    job_name_nums.push(res[i].job_name_num);
                }
                myChart.setOption({
                    xAxis: {
                        data: job_names
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: '数量',
                        data: job_name_nums
                    }]
                });
            }
        });

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
    function js2() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('js2'));

        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            toolbox: {

                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: [],
                    axisTick: {
                        alignWithLabel: true,
                        axisTick: { //关键设置，坐标轴刻度也不显示
                            show: false
                        },
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLine: { //关键设置，不显示X轴线条
                        show: false
                    },
                }
            ],
            series: [
                {
                    name: '数量',
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            color: function(params) {
                                // 给出颜色组
                                var colorList = ['#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6','#1cc09f','#A6A6A6'];
                                return colorList[params.dataIndex]
                            },
                        }
                    },
                    data: []
                }
            ]
        };
        // 定义x、y轴数据数组

        var workareas=[];
        var workarea_nums=[];
        //请求后台数据
        $.ajax({
            type : "post",
            async : true,
            url: "/index/workarea/"+targetPageId,
            dataType : "json",
            contentType: "application/json",
            success: function(res){
                console.log(res);
                for (var i = 0; i < res.length ; i++) {
                    workareas.push(res[i].workarea);
                    workarea_nums.push(res[i].workarea_num);
                }
                myChart.setOption({
                    xAxis: {
                        data: workareas
                    },
                    series: [{
                        // 根据名字对应到相应的系列
                        name: '数量',
                        data: workarea_nums
                    }]
                });
            }
        });

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }

})